<?php
require_once("lib/auth/session.php");
require_once("lib/sqlConnector.php");

// updates rating for $postid with new average rating
function updateRating($postid, $newRating) {
	//$result = sqlQuery("SELECT ratings, numberofratings FROM posts WHERE postid = '$postid'");
	//$old = mysql_fetch_assoc($result);
	//$updatedRating = ($old['rating'] * $old['numberofratings'] + $newRating) / ($old['numberofratings'] + 1);
	sqlQuery("UPDATE posts SET rating = ((rating * numberofratings + '%s') / 
	(numberofratings + 1)), numberofratings = (numberofratings + 1) WHERE postid = '%s'",array($newRating,$postid));
	$updatedRating = mysql_fetch_row(sqlQuery("SELECT rating FROM posts WHERE postid = '%s'", $postid));
	return $updatedRating[0];
}

?>